package soccer.action;



import java.util.List;
import java.util.Map;

import soccer.model.matches.Match;
import soccer.model.matches.MatchDAOImpl;
import soccer.model.player.Player;
import soccer.model.player.PlayerDAOImpl;
import soccer.model.team.Team;
import soccer.model.team.TeamDAOImpl;


import soccer.model.admin.Admin;
import soccer.model.admin.AdminDAOImpl;
import soccer.model.coach.Coach;
import soccer.model.coach.CoachDAOImpl;

public class AdminActions {
	
	 public int addCoach(String name, String surname, String birthPlace, String birthDate ,
				String aggremtBegin, String aggrementFinish){
		Coach coach=new Coach(name,  surname,  birthPlace,  birthDate ,
				 aggremtBegin,  aggrementFinish);
		CoachDAOImpl coachDAOImpl=new CoachDAOImpl();
		int rows=coachDAOImpl.enterCoach(coach);
		 return rows;
		 
	 }
	 public int addCoach(String name, String surname, String birthPlace, String birthDate ,
				String aggremtBegin, String aggrementFinish,String teamName){
		 Coach coach=new Coach(name,  surname,  birthPlace,  birthDate ,
				 aggremtBegin,  aggrementFinish);
		 TeamDAOImpl teamDAOImpl=new TeamDAOImpl();
		 Map team=teamDAOImpl.searchTeamByName(teamName).get(0);
		 int teamCode=(Integer) team.get("teamkodu");
		CoachDAOImpl coachDAOImpl=new CoachDAOImpl();
		int rows=coachDAOImpl.enterCoach(coach,teamCode);
		 return rows;
		
	 }
	 
	 public int addTeamsMatch(Team homeTeamName,Team awayTeamName,int week,String date){
		 Match match=new Match(homeTeamName,awayTeamName,week,date);
		 TeamDAOImpl teamDAOImpl=new TeamDAOImpl();
		 Map team=teamDAOImpl.searchTeamByName(homeTeamName.toString()).get(0);
		 Map team2=teamDAOImpl.searchTeamByName(awayTeamName.toString()).get(0);
		 int teamCode=(Integer) team.get("teamkodu");
		 MatchDAOImpl matchDAOImpl=new MatchDAOImpl();
		 int rows=matchDAOImpl.enterMatch(match);
		 return rows;
	 }
	 
	 public int addPlayer(String name ,String surname , String birthDate,  String birthPlace , int licenceNo){
		 Player player = new Player(name, surname, birthPlace, birthDate, licenceNo);
		 PlayerDAOImpl playerDAOImpl = new PlayerDAOImpl();
		 int rows = playerDAOImpl.enterPlayer(player);
		 return rows;
	 }
	 public int addPlayer(String name , String surname , String birthDate ,String birthPlace , int licenceNo ,
		String teamName , String licenceBeginDate ,String licenceFinishDate){
		Player player = new Player(name, surname, birthPlace, birthDate, licenceNo, licenceBeginDate, licenceFinishDate);
	    TeamDAOImpl teamDAOImpl = new TeamDAOImpl();
	    Map team = teamDAOImpl.searchTeamByName(teamName).get(0);
	    int teamCode = (Integer) team.get("teamkodu");
	    PlayerDAOImpl playerDAOImpl = new PlayerDAOImpl();
	    int rows = playerDAOImpl.insertPlayerWithTeam(player, teamCode);
	    return rows;
	  }
	 public boolean login(int password , String name){
		 Admin admin = new Admin(password, name);
		 AdminDAOImpl adminDAOImpl = new AdminDAOImpl();
		 List ls =  adminDAOImpl.controlPassword(admin);
		 if(ls == null || ls.size() < 1 ){
			 return false;
		 }
		 return true;
	 }
	 
	public int create(int password, String nickname, String name,
			String surname, String birthdate, String birthplace) {
		// TODO Auto-generated method stub
		 Admin admin=new Admin(password,nickname,name,surname,birthdate,birthplace);
		 AdminDAOImpl adminDAOImpl=new AdminDAOImpl();
		int res= adminDAOImpl.create(admin);
		 	return res;
	}
	public int addCoach(String name, String surname, String birthplace,
			String birthdate) {
		// TODO Auto-generated method stub
		Coach coach=new Coach(name,  surname,  birthplace,  birthdate);
		CoachDAOImpl coachDAOImpl=new CoachDAOImpl();
		int rows=coachDAOImpl.enterCoach(coach);
		 return rows;
		
	}

}
